package com.example.ddd.domain.model.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Product {
    private Long id;
    private String name;
    private String description;
    private BigDecimal price;
    private Integer stock;
    
    // 领域行为
    public boolean isAvailable() {
        return stock > 0;
    }
    
    public void decreaseStock(int quantity) {
        if (quantity <= 0) {
            throw new IllegalArgumentException("减少的库存数量必须大于0");
        }
        
        if (quantity > stock) {
            throw new IllegalArgumentException("库存不足");
        }
        
        this.stock -= quantity;
    }
    
    public void increaseStock(int quantity) {
        if (quantity <= 0) {
            throw new IllegalArgumentException("增加的库存数量必须大于0");
        }
        
        this.stock += quantity;
    }
}